package com.wn.procurement.rabbitmq;

import com.rabbitmq.client.Channel;
import com.wn.entity.Procurement;
import com.wn.procurement.mapper.ProcurementMapper;
import org.apache.logging.log4j.message.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class Consumer {
    @Autowired
    private ProcurementMapper procurementMapper;

    @Autowired
    RedisTemplate<String, Object> redisTemplate;

    /**
     * @param procurement  object obj,消息正文 发送的什么类型就要用什么类型接受
     * @param message Message message, 消息对象 包含编码格式 头信息等等
     * @param channel Channel channel, 信道
     * @return void
     * @ author lmz
     * @ date 2022/10/27 13:44
     * @ Description 添加库存台账信息 并删除库存台账缓存
     */
    @RabbitListener(queues = "queueprocurement")
    public void receive(Procurement procurement, Message message, Channel channel) {
        procurementMapper.insert(procurement);
        HashOperations<String, Object, Object> hash = redisTemplate.opsForHash();
        hash.delete("procurement");
    }
}
